﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Yes.Application;

namespace Yes.Web.Blog.Attribute
{
    public class GlobalActionFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!filterContext.ModelState.IsValid)
            {
                filterContext.Result = new JsonResult(new { ErrorMessage = "参数验证失败", Status = false, Data = filterContext.ModelState.Values.SelectMany(v => v.Errors).Select(p => p.ErrorMessage) });
            }
        }
    }
}